import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.hong.h11.entity.Student;
import org.hong.h11.mapper.StudentMapper;
import org.junit.Test;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

public class hong {
    @Test
    public void testDynamicSQL() throws IOException {
        SqlSession SqlSession = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml")).openSession();
       StudentMapper userMapper = SqlSession.getMapper(StudentMapper.class);

        Student student = new Student();
        student.setName("hong");
        student.setStudentId("202303230111");
        student.setClassName("软件231");
        student.setGender("男");
        student.setAge(18);
        int i = userMapper.insertOne(student);
        SqlSession.commit();
        System.out.println(i);

        List<Student> students = userMapper.allStudents();
        System.out.println(students);

          Student student01 = new Student();
          //逐行测试即可
          student01.setStudentId("202303230111");
          student01.setClassName("软件231");
          student01.setGender("男");
          Student student1 = userMapper.findByOne(student01);
          System.out.println(student1);

          int i01 = userMapper.delete(1);

    }
    @Test
    public void testo() {
        String url = "jdbc:mysql://localhost:3306/hong_run";
        String user = "root";
        String password = "root";

        try (Connection conn = DriverManager.getConnection(url, user, password)) {
            System.out.println("数据库连接成功！");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}